/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vehicle.bol;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import vehicle.dal.DAL;
import vehicle.entity.Customer;
import vehicle.entity.Vehicles;

/**
 *
 * @author lab1
 */
public class CarBOL {

    public List<Vehicles> showAllVehicle() {
        DAL dal = new DAL();
        List<Vehicles> listVe = new ArrayList<Vehicles>();
        try {
            ResultSet rs = dal.executeQuery("showAllVehicle", new ArrayList());
            while (rs.next()) {
                Vehicles ve = new Vehicles();
                ve.setVehicleID(rs.getInt("VehicleID"));
                ve.setVehilceName(rs.getString("VehicleName"));
                ve.setModulNumber(rs.getString("ModelNumber"));
                ve.setTypeID(rs.getInt("TypeID"));
                ve.setPrice(rs.getDouble("Price"));
                ve.setCylinder(rs.getString("Cylinder"));
                ve.setGearBox(rs.getString("GearBox"));
                ve.setSeries(rs.getString("Series"));
                ve.setCombustible(rs.getString("Combustible"));
                ve.setSeat(rs.getInt("Seat"));
                ve.setColor(rs.getString("Color"));
                ve.setQuantity(rs.getInt("Quantity"));
                ve.setImage(rs.getString("ImgUrl"));
                ve.setStatus(rs.getInt("STATUS"));
                listVe.add(ve);
            }
        } catch (Exception e) {
        } finally {
            dal.closeConnection();
        }
        return listVe;
    }

    public List<Vehicles> showstatisticsVehicle() {
        DAL dal = new DAL();
        List<Vehicles> listVe = new ArrayList<Vehicles>();
        try {
            ResultSet rs = dal.executeQuery("showstatisticsVehicle", new ArrayList());
            while (rs.next()) {
                Vehicles ve = new Vehicles();
                ve.setVehicleID(rs.getInt("VehicleID"));
                ve.setVehilceName(rs.getString("VehicleName"));
                ve.setModulNumber(rs.getString("ModelNumber"));
                ve.setTypeID(rs.getInt("TypeID"));
                ve.setPrice(rs.getDouble("Price"));
                ve.setCylinder(rs.getString("Cylinder"));
                ve.setGearBox(rs.getString("GearBox"));
                ve.setSeries(rs.getString("Series"));
                ve.setCombustible(rs.getString("Combustible"));
                ve.setSeat(rs.getInt("Seat"));
                ve.setColor(rs.getString("Color"));
                ve.setQuantity(rs.getInt("Quantity"));
                ve.setImage(rs.getString("ImgUrl"));
                ve.setStatus(rs.getInt("STATUS"));
                ve.setStatistic(rs.getInt("statistic"));
                listVe.add(ve);
            }
        } catch (Exception e) {
        } finally {
            dal.closeConnection();
        }
        return listVe;
    }

    public List<Vehicles> searchCarByVehicleName(String nameorid, String valueSearch) {
        DAL dal = new DAL();
        List<Vehicles> listVe = new ArrayList<Vehicles>();
        ArrayList a = new ArrayList();
        a.add(valueSearch);
        String stor = "";
        if (nameorid.equals("name")) {
            stor = "searchCarByVehicleName";
        } else {
            stor = "usp_Get_Vehicle_By_TypeVehicle";
        }
        try {
            ResultSet rs = dal.executeQuery(stor, a);
            while (rs.next()) {
                Vehicles ve = new Vehicles();
                ve.setVehicleID(rs.getInt("VehicleID"));
                ve.setVehilceName(rs.getString("VehicleName"));
                ve.setModulNumber(rs.getString("ModelNumber"));
                ve.setTypeID(rs.getInt("TypeID"));
                ve.setPrice(rs.getDouble("Price"));
                ve.setCylinder(rs.getString("Cylinder"));
                ve.setGearBox(rs.getString("GearBox"));
                ve.setSeries(rs.getString("Series"));
                ve.setCombustible(rs.getString("Combustible"));
                ve.setSeat(rs.getInt("Seat"));
                ve.setColor(rs.getString("Color"));
                ve.setQuantity(rs.getInt("Quantity"));
                ve.setImage(rs.getString("ImgUrl"));
                ve.setStatus(rs.getInt("STATUS"));
                listVe.add(ve);
            }
        } catch (Exception e) {
        } finally {
            dal.closeConnection();
        }
        return listVe;
    }

    public List<String> showAbumByVehicleID(int vehicleID) {
        DAL dal = new DAL();
        List<String> listVe = new ArrayList<String>();
        ArrayList a = new ArrayList();
        a.add(vehicleID);
        try {
            ResultSet rs = dal.executeQuery("showAbumByVehicleID", a);
            while (rs.next()) {
                listVe.add(rs.getString("ImgUrl"));
            }
        } catch (Exception e) {
        } finally {
            dal.closeConnection();
        }
        return listVe;
    }

    public int OrderAndCustomer(Customer cus, int vehicleID) {

        return 0;
    }

    public List<Vehicles> showPosition(int brandID) {
        DAL dal = new DAL();
        List<Vehicles> listVe = new ArrayList<Vehicles>();
        ArrayList a = new ArrayList();
        a.add(brandID);
        try {
            ResultSet rs = dal.executeQuery("showPosition", a);
            while (rs.next()) {
                Vehicles ve = new Vehicles();
                ve.setVehicleID(rs.getInt("VehicleID"));
                ve.setVehilceName(rs.getString("VehicleName"));
                ve.setModulNumber(rs.getString("ModelNumber"));
                ve.setTypeID(rs.getInt("TypeID"));
                ve.setPrice(rs.getDouble("Price"));
                ve.setCylinder(rs.getString("Cylinder"));
                ve.setGearBox(rs.getString("GearBox"));
                ve.setSeries(rs.getString("Series"));
                ve.setCombustible(rs.getString("Combustible"));
                ve.setSeat(rs.getInt("Seat"));
                ve.setColor(rs.getString("Color"));
                ve.setQuantity(rs.getInt("Quantity"));
                ve.setImage(rs.getString("ImgUrl"));
                ve.setStatus(rs.getInt("STATUS"));
                listVe.add(ve);
            }
        } catch (Exception e) {
        } finally {
            dal.closeConnection();
        }
        return listVe;
    }

    public static Vehicles searchVehicleByID(int vehicleID) {
        DAL dal = new DAL();
        Vehicles ve = new Vehicles();
        ArrayList a = new ArrayList();
        a.add(vehicleID);
        try {
            ResultSet rs = dal.executeQuery("searchVehicleByID", a);
            while (rs.next()) {
                ve = new Vehicles();
                ve.setVehicleID(rs.getInt("VehicleID"));
                ve.setVehilceName(rs.getString("VehicleName"));
                ve.setModulNumber(rs.getString("ModelNumber"));
                ve.setTypeID(rs.getInt("TypeID"));
                ve.setPrice(rs.getDouble("Price"));
                ve.setCylinder(rs.getString("Cylinder"));
                ve.setGearBox(rs.getString("GearBox"));
                ve.setSeries(rs.getString("Series"));
                ve.setCombustible(rs.getString("Combustible"));
                ve.setSeat(rs.getInt("Seat"));
                ve.setColor(rs.getString("Color"));
                ve.setQuantity(rs.getInt("Quantity"));
                ve.setImage(rs.getString("ImgUrl"));
                ve.setStatus(rs.getInt("STATUS"));
                return ve;
            }
        } catch (Exception e) {
        } finally {
            dal.closeConnection();
        }
        return ve;
    }

    public int editPriceVehicle(int vehicleID, double price) {
        DAL dal = new DAL();
        ArrayList ar = new ArrayList();
        ar.add(vehicleID);
        ar.add(price);
        int a = 0;
        try {
            a = dal.executeUpdateQuery("editPriceVehicle", ar);

        } catch (Exception e) {
        } finally {
            dal.closeConnection();
        }
        return a;
    }
    /*
     *Add New Vehicle
     */

    public boolean addNewVehicle(Vehicles vehicles) {
        boolean flag = false;
        DAL dal = new DAL();
        ArrayList listParam = new ArrayList();
        listParam.add(vehicles.getVehilceName());
        listParam.add(vehicles.getModulNumber());
        vehicles.setTypeID(vehicles.getTypeID());
        listParam.add(vehicles.getTypeID());
        listParam.add(vehicles.getPrice());
        listParam.add(vehicles.getCylinder());
        listParam.add(vehicles.getGearBox());
        listParam.add(vehicles.getSeries());
        listParam.add(vehicles.getCombustible());
        listParam.add(vehicles.getSeat());
        listParam.add(vehicles.getColor());
        listParam.add(vehicles.getQuantity());
        try {
            dal.executeUpdateQuery("sp_addVehicle", listParam);
            flag = true;
        } catch (Exception e) {
            flag = false;
        }
        //
        return flag;
    }
}
